package cn.itcast.ssm.controller;

import cn.itcast.ssm.domain.Product;
import cn.itcast.ssm.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private IProductService productService;

    @RequestMapping("/findAll.do")
    public ModelAndView findAll(){
        ModelAndView mv = new ModelAndView();
        mv.addObject("productList", productService.findAll());
        mv.setViewName("product-list");
        return mv;
    }

    @RequestMapping("/save.do")
    public ModelAndView save(Product product){
        ModelAndView mv = new ModelAndView();
        productService.save(product);
        //重定向到产品列表页
        mv.setViewName("redirect:/product/findAll.do");
        return mv;
    }
}
